package demo3;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-07-16
 * Time: 12:39
 */
public class Test {
    public static void main(String[] args) {
        String date = "2025-05-05 01:20:20";
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime localDateTime = LocalDateTime.parse(date,dateTimeFormatter);
        System.out.println(localDateTime);
    }
    public static void main4(String[] args) {
        LocalDateTime beingDate = LocalDateTime.of(2025,1,2,3,4);
        System.out.println(beingDate);//2025-01-02T03:04
    }
    public static void main3(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        int year = now.getYear();
        int month = now.getMonthValue();
        int day = now.getDayOfMonth();
        int hour = now.getHour();
        int minute = now.getMinute();
        int second = now.getSecond();
        System.out.println(year);
        System.out.println(month);
        System.out.println(day);
        System.out.println(hour);
        System.out.println(minute);
        System.out.println(second);
    }
    public static void main2(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
    }
    public static void main1(String[] args) {
        //获取当前日期和时间
        LocalDateTime now = LocalDateTime.now();
        //获取指定日期和时间
        LocalDateTime dateTime = LocalDateTime.of(2025,7,16,12,54);
        //从字符串解析
        LocalDateTime parsed = LocalDateTime.parse("2025-07-16T12:55:00");
        System.out.println(now);
        System.out.println(dateTime);
        System.out.println(parsed);
    }
}
